import 'package:favorcate/core/viewmodel/filter_view_model.dart';
import 'package:flutter/material.dart';

import 'package:favorcate/ui/shared/extension/int_extension.dart';
import 'package:provider/provider.dart';

class ZSFilterContent extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Column(
      children: [buildChoiceTitle(context), buildChoiceSelect()],
    );
  }

  Widget buildChoiceTitle(BuildContext context) {
    return Container(
      padding: EdgeInsets.all(20.px),
      alignment: Alignment.center,
      child: Text(
        '展示你的样式',
        style: Theme.of(context)
            .textTheme
            .headline2
            ?.copyWith(fontWeight: FontWeight.bold),
      ),
    );
  }

  Widget buildChoiceSelect() {
    return Expanded(
      child: Consumer<ZSFilterViewModel>(
        builder: (ctx, filterVM, child) {
          return ListView(children: [
            buildListTile('无谷蛋白', '展示无谷蛋白食物', filterVM.isGlutenFree, (value) {
              filterVM.isGlutenFree = value;
            }),
            buildListTile('不含乳糖', '展示不含乳糖食物', filterVM.isLactoseFree, (value) {
              filterVM.isLactoseFree = value;
            }),
            buildListTile('普通食宿者', '展示普通食宿相关食物', filterVM.isVegetarian,
                (value) {
              filterVM.isVegetarian = value;
            }),
            buildListTile('严格素食者', '展示严格素食相关食物', filterVM.isVegan, (value) {
              filterVM.isVegan = value;
            }),
          ]);
        },
      ),
    );
  }

  Widget buildListTile(
      String title, String subTitle, bool value, Function(bool) onChange) {
    return ListTile(
      title: Text(title),
      subtitle: Text(subTitle),
      trailing: Switch(value: value, onChanged: onChange),
    );
  }
}
